package org.jeecg.modules.health_code.entity.sm.response;

import java.io.Serializable;



import cn.hutool.json.JSONUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 
 * 返回结果对象
 * 
 * @author  farman.zhang
 * @version  [版本号, 2019年2月18日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@ApiModel(description = "返回的对象")
@Data
public class Result<T> implements Serializable
{
    
    private static final long serialVersionUID = -2570841464587584664L;

    /**
     * 返回编码
     */
    @ApiModelProperty(value = "返回编码,10000成功，其它值为失败")
    private String respCode;
    
    /**
     * 返回描述
     */
    @ApiModelProperty(value = "返回描述")
    private String respDesc;
    
    /**
     * 返回实体数据
     */
    @ApiModelProperty(value = "返回实体对象,请对返回的respData进行空值判断，如果respCode为10000但respData为空，则也是失败的,请注意！！")
    private T respData;
    
    public Result()
    {
    }
    
    public Result(String respCode, String respDesc)
    {
        this.respCode = respCode;
        this.respDesc = respDesc;
    }
    
    public Result(String respCode, String respDesc, T respData)
    {
        this.respCode = respCode;
        this.respDesc = respDesc;
        this.respData = respData;
    }
    
    public static <T> Result<T> returnOk(T t)
    {
        return new Result<>("10000", "成功", t);
    }
    
    public static <T> Result<T> returnFail(T t)
    {
        return new Result<>("00", "失败", t);
    }
    @Override
    public String toString()
    {
        
        return JSONUtil.toJsonStr(this);
    }
}
